package br.cin.ufpe.corba.exmaples.complex;

import java.io.IOException;

import br.cin.ufpe.corba.ORB;
import br.cin.ufpe.corba.namingservice.NamingContext;
import br.cin.ufpe.corba.namingservice.NamingContextExt;
import br.cin.ufpe.corba.namingservice.NamingContextHelper;

public class Server {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		ORB orb = ORB.init(1136, "localhost", 1133);

		SimpleCalculatorImpl simple = new SimpleCalculatorImpl(orb);
		ComplexCalculatorImpl complex = new ComplexCalculatorImpl(orb);
				
		NamingContextExt nc = NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
		
		NamingContext cinNamingContext = nc.bind_new_context(nc.to_name("calculadoras"));
		cinNamingContext.bind(nc.to_name("Simples"), simple);
		System.out.println("Calculadora Simples service is running...");
		
		cinNamingContext.bind(nc.to_name("Complexa"), complex);
		System.out.println("Calculadora Complexa service is running...");
		
		System.out.println("Press a key to close the server.");
		System.in.read();
	}

}
